<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form method="get" action="/page" style="display: inline">
    图书名称：<input type="text" name="name" th:value="${book.name}">
    图书类别：<input type="text" name="category" th:value="${book.category}">
    图书作者：<input type="text" name="author" th:value="${book.author}">
    <input type="submit" value="查询"/>
</form>
<button onclick="add()">新增</button>
<table border="1">
    <tr>
        <th>选择</th>
        <th>编号</th>
        <th>书名</th>
        <th>价格</th>
        <th>类目</th>
        <th>库存</th>
        <th>图片</th>
        <th>说明</th>
        <th>作者</th>
        <th>已售</th>
        <th>操作</th>
    </tr>
    <form th:action="@{/del}" method="post" onsubmit="return validateForm()">
    <tr th:each="b:${books.records}">
        <td>
            <input type="checkbox" th:value="${b.id}" name="ids">
        </td>
        <td th:text="${b.id}"></td>
        <td th:text="${b.name}"></td>
        <td th:text="${b.price}"></td>
        <td th:text="${b.category}"></td>
        <td th:text="${b.pnum}"></td>
        <td th:text="${b.imgurl}"></td>
        <td th:text="${b.description}"></td>
        <td th:text="${b.author}"></td>
        <td th:text="${b.sales}"></td>
        <td>
            <a th:href="@{/update(id=${b.id})}">
                修改
            </a>
        </td>
    </tr>
        <input type="submit" value="删除" onsubmit="return validateForm()">
    </form>
</table>
总页数：<span th:text="${books.pages}"></span>
总记录数：<span th:text="${books.total}"></span>
当前页：<span th:text="${books.current}"></span>
&nbsp;&nbsp;&nbsp;&nbsp;
<span th:if="${books.current>1}">
    <a th:href="@{/page(pageNum=${books.current -1},name=${book.name},category=${book.category},author=${book.author})}">上一页</a>
</span>
<span th:each="p:${#numbers.sequence(1,books.pages)}">
    <a th:href="@{/page(pageNum=${p},name=${book.name},category=${book.category},author=${book.author})}" th:text="${p}"></a>
</span>
<span th:if="${books.current<books.pages}">
    <a th:href="@{/page(pageNum=${books.current+1},name=${book.name},category=${book.category},author=${book.author})}">下一页</a>
</span>
</body>
<script src="/js/jquery-3.5.1.js"></script>
<script>
    function validateForm(){
        if ($("input[name='ids']:checked").length==0){
            alert("必须选一个")
            return false
        }
        if (confirm("确定要删除吗？")) {
        }else {
            alert("已取消删除")
            return false
        }
    }
    function add() {
        window.location.href = "/add";
    }
</script>
</html>